package com.example.date;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @author hej
 * @date 2025/1/9 15:24
 */
public class DateDom {
    /*
        根据当前日期对应1970,1,1日天数转为34进制得出相应编码
     */
    public static void main(String[] args) {
        getDateCode();
    }

    public static void getDateCode() {
        LocalDateTime time1 = LocalDateTime.of(1970,1,1,0,0);
        LocalDateTime time2 = LocalDateTime.of(1973,3,3,23,23);
        long daysBetween = ChronoUnit.DAYS.between(time1, time2);
        System.out.println("Days between: " + daysBetween);
        System.out.println(convertToBase34((int)daysBetween));
    }

    public static String convertToBase34(int number) {
        if (number < 0 || number >= 39303) { // 检查范围
            //throw new IllegalArgumentException("数字必须在0到39302之间");
        }
        //先取模，防止刁民   34 ^ 3
        number = number % 39304;

        char[] base34Chars = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ".toCharArray();
        StringBuilder result = new StringBuilder();

        // 转换为34进制
        do {
            //每次循环取到当前number个位数
            int remainder = number % 34;
            result.insert(0, base34Chars[remainder]);
            number /= 34;
        } while (number > 0);

        // 确保结果是三位数，不足的用0填充
        while (result.length() < 3) {
            result.insert(0, '0');
        }

        return result.toString();
    }
}
